/**
 * @fileoverview Helper function copied from externalpage.htm from
 *     amazon mechical's command line tool.
 */

/**
 * This method Gets URL Parameters (GUP)
 */
function gup (name) {
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if (results == null) {
    return "";
  }
  return results[1];
}

/**
 * This method decodes the query parameters that were URL-encoded
 */
function decode (strToDecode) {
  var encoded = strToDecode;
  return unescape(encoded.replace(/\+/g,  " "));
}

function initHit() {
  if (gup('assignmentId') == 'ASSIGNMENT_ID_NOT_AVAILABLE') {
    createPreview();
  } else {
    initTurkIds();
    initLogger();
    createFrontPage();
  }
}

function initTurkIds() {
  /*turkIds = {
    assignId: gup('assignmentId'),
    hitId: gup('hitId'),
    workerId: gup('workerId')
  };*/
  assignId = gup('assignmentId');
  turkSubmitTo = gup('turkSubmitTo');
}
